


#栅栏函数
def generate_w(string, n):
    '''将字符排列成w型'''
    array = [['.']*len(string) for i in range(n)] #生成初始矩阵
    row = 0
    upflag = False
    for col in range(len(string)): #在矩阵上按w型画出string
        array[row][col] = string[col]
        if row == n-1:
            upflag = True
        if row == 0:
            upflag = False
        if upflag:
            row -= 1
        else:
            row += 1
    return array

def encode(string, n):
    '''加密'''
    array = generate_w(string, n)
    msg = []
    for row in range(n): #将每行的字符连起来
        for col in range(len(string)):
            if array[row][col] != '.':
                msg.append(array[row][col])
    return array, msg
def decode(string, n):
    '''解密'''
    array = generate_w(string, n)
    sub = 0
    for row in range(n): #将w型字符按行的顺序依次替换为string
        for col in range(len(string)):
            if array[row][col] != '.':
                array[row][col] = string[sub]
                sub += 1
    msg = []
    for col in range(len(string)): #以列的顺序依次连接各字符
        for row in range(n):
            if array[row][col] != '.':
                msg.append(array[row][col])
    return array, msg
def wzhalan_def(string):
    '''列出所有'''
    m_lt=""
    for n in range(2,len(string)): #遍历所有可能的栏数
        m_lt+=(str(n)+'栏：'+''.join(decode(string, n)[1])+"\n")
    return m_lt

def wzhalan_def1(string):
    '''23栏'''
    m_lt=""
    m_lt+=(''.join(decode(string, 23)[1]))
    return m_lt

#凯撒函数
def caesar(plaintext,x):
    str_list = list(plaintext)
    i = 0
    while i < len(plaintext):
        if not str_list[i].isalpha():
            str_list[i] = str_list[i]
        else:
            a = "A" if str_list[i].isupper() else "a"
            str_list[i] = chr((ord(str_list[i]) - ord(a) - x) % 26 + ord(a) or 5)
        i = i + 1

    return ''.join(str_list)

a1='SWZxWl=F=DQef0hlEiSUIVh9ESCcMFS9NF2NXFzM'

a1=wzhalan_def1(a1)
print(a1)
import base64
a1=base64.b64decode(a1).decode()
print(a1)

for i in range(26):
    a2=caesar(a1,i)
    if "CTF" in a2:
        print(a2)
        break